#!/bin/sh

. server_config.sh

ARG="$1"
ARG2="$2"
WORKLOAD="none"

echo Arg 1 is $ARG

if [ "$ARG2" = "none" ]; then
    ARG2 = "0"
fi

if [ "$ARG" = "1" ]; then
    echo Using 1 user workload file.
    WORKLOAD="tests/1userWorkLoad"
fi

if [ "$ARG" = "2" ]; then
    echo Using 2 user workload file.
    WORKLOAD="tests/2userWorkLoad"
fi

if [ "$ARG" = "10" ]; then
    echo Using 10 user workload file.
    WORKLOAD="tests/10User_testWorkLoad"
fi

if [ "$ARG" = "45" ]; then
    echo Using 45 user workload file.
    WORKLOAD="tests/45User_testWorkLoad"
fi

if [ "$ARG" = "1000" ]; then
    echo Using 1000 user workload file
    if [ ! -e /tmp/$LOGNAME/1000User_testWorkLoad ]; then
        mkdir /tmp/$LOGNAME
        cp -f tests/1000User_testWorkLoad.gz /tmp/$LOGNAME/
        pushd /tmp/$LOGNAME
        gunzip 1000User_testWorkLoad.gz
        popd
    fi
    WORKLOAD="/tmp/$LOGNAME/1000User_testWorkLoad"
fi

if [ "$ARG" = "final" ]; then
    echo Using final workload file
    if [ ! -e /tmp/group2/final_testWorkLoad ]; then
        cp -f tests/final_testWorkLoad.gz /tmp/group2/
        pushd /tmp/group2
        gunzip final_testWorkLoad.gz
        popd
    fi
    WORKLOAD="/tmp/group2/1000user_testWorkLoad"
fi

if [ "$WORKLOAD" = "none" ]; then
    echo Usage: runtests.sh command
    echo command is one of 1, 2, 10, 45, 1000, or final
else
    echo Workload file is $WORKLOAD, writing output to testoutput.txt

    $JAVA_CMD ca.uvic.group2.testHarness.Main $WORKLOAD $ARG2
fi

